package com.fulin.thread.semaphore;

import java.util.concurrent.Semaphore;

public class TestSemaphore {
	public static void main(String[] args) {
		Semaphore semaphore = new Semaphore(5);
		try {
			semaphore.acquire();
			semaphore.acquire();
			semaphore.acquire();
			semaphore.acquire();
			semaphore.acquire();
			semaphore.release();
			System.out.println("现在的许可数量: "+semaphore.availablePermits());
			
			semaphore.release();
			semaphore.release();
			semaphore.release();
			semaphore.release();
			semaphore.release();
			semaphore.release();
			semaphore.release();
			System.out.println("现在的许可数量: "+semaphore.availablePermits());
			
			semaphore.release(4);
			System.out.println("现在的许可数量: "+semaphore.availablePermits());
		} catch (InterruptedException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
}
